#include <fstream>
#include <string>
#include <cstring>

#include "string_intf.h"


int main(int argc, char **argv)
{
    char line_buffer[256] = {0};
    std::vector<std::string> points_lines, query_xy_lines;

    if (argc < 3) {
        return -1;
    }

    std::ifstream points_input_stream(argv[1]);
    std::ifstream query_xy_input_stream(argv[2]);

    while (!points_input_stream.eof()) {
        points_input_stream.getline(line_buffer, 256);
        if (strlen(line_buffer) == 0) {
            continue;
        }
        points_lines.push_back(std::string(line_buffer));
    }

    while (!query_xy_input_stream.eof()) {
        query_xy_input_stream.getline(line_buffer, 256);
        if (strlen(line_buffer) == 0) {
            continue;
        }
        query_xy_lines.push_back(std::string(line_buffer));
    }

    StringIntf intf = StringIntf(points_lines);
    intf.Triangulation();

    for (auto& query_xy_line : query_xy_lines) {
        std::cout << intf.QueryZ(query_xy_line) << std::endl;
    }

    return 0;
}
